;(function(){
	'use strict';
	angular.module('services.workOrderData.auditData',[])
	.factory('auditDataService',auditDataService);
	function auditDataService(Restangular){
		return {
			fmtDateTitle: fmtDateTitle,
			queryWorkDataType: queryWorkDataType,
			queryStatisticsType: queryStatisticsType,
			getName: getName,
			getStatisticsTypeName: getStatisticsTypeName
		};
		function fmtDateTitle(send){
	      var timeTitle = '';
	      var startYear = send.startTime.substring(0, 4)+'年';
	      var endYear = send.endTime.substring(0, 4)+'年';
	      var startMonth = send.startTime.substring(5, 7)+'月';
	      var endMonth = send.endTime.substring(5, 7)+'月';
	      var startDay = send.startTime.substring(8, 10)+'日';
      	  var endDay = send.endTime.substring(8, 10)+'日';
	      var booleanYear = startYear === endYear;
	      var booleanMonth = startMonth === endMonth;
	      var booleanDay = startDay === endDay; 
		  timeTitle = booleanYear && booleanMonth && booleanDay ? startYear + startMonth + startDay : startYear + startMonth + startDay + ' 至 ' + endYear + endMonth + endDay;   
	      return timeTitle;
	    }
	    //查询工单类型
		function queryWorkDataType(callback){
			Restangular.one('sas/common/queryWorkDataType').get().then(callback);
		}
		//查询统计维度
		function queryStatisticsType(params,callback){
			Restangular.all('sas/common/queryStatisticsType').post(params).then(callback);
		}
		//根据工单类型code获取所对应的名字
	    function getName(code,workDataTypes){
	      var name = '';
	      if(code){
	        angular.forEach(workDataTypes,function(res){
	          if(res.workOrderTypeCode === code){
	            name = res.workOrderTypeName;
	          }
	        });
	      }
	      return name;
	    }
	    //根据统计维度code获取所对应的名字
	    function getStatisticsTypeName(code,statisticsTypes){
	      var name = '';
	      if(code){
	        angular.forEach(statisticsTypes,function(res){
	          if(res.statisticsTypeCode === code){
	            name = res.statisticsTypeName;
	          }
	        });
	      }
	      return name;
	    }
	}
})();